home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 June: System Software / Dev.CD Jun 97 SSW.toast / What's New? / Sample Code / Text / NeoTextBox97 / Utilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-23  |  4.5 KB  |  180 lines  |  [TEXT/CWIE]

  1. /*****************************************************************************************
  2.  
  3. Utilities.c - utility routines for NTBDemo
  4.  
  5. Written by Bryan K. Ressler (Beaker), 8/30/91
  6.  
  7. updated for the wonderful universe of PowerPC by Pete Gontier (Gurgle), 3/31/97
  8.  
  9. *****************************************************************************************/
  10.  
  11. /** INCLUDES ****************************************************************************/
  12. #include "NTBDemo.h"            /* NTBDemo stuff */
  13. #include "NeoTextBox.h"
  14. #include "Utilities.h"
  15.  
  16. #ifndef __TEXTEDIT__
  17. #    include <TextEdit.h>
  18. #endif
  19.  
  20. #ifndef __FONTS__
  21. #    include <Fonts.h>
  22. #endif
  23.  
  24. /****************************************************************************************/
  25. short JustToRadio(short justification)
  26. {
  27.     short result = kJustFull;
  28.  
  29.     switch (justification)
  30.     {
  31.         case teJustLeft:
  32.             result = kJustLeft;
  33.             break;
  34.         case teJustCenter:
  35.             result = kJustCenter;
  36.             break;
  37.         case teJustRight:
  38.             result = kJustRight;
  39.             break;
  40.         case ntbJustFull:
  41.             result = kJustFull;
  42.             break;
  43.     }
  44.  
  45.     return result;
  46. }
  47.  
  48. /****************************************************************************************/
  49. short RadioToJust(void)
  50. {
  51.     static short justifications[4] = { teJustLeft,teJustCenter,teJustRight,ntbJustFull };
  52.     return (justifications[gJustRadio - kJustLeft]);
  53. }
  54.  
  55. /****************************************************************************************/
  56. short RadioToFont(void)
  57. {
  58.     short familyID = GetAppFont();
  59.     
  60.     switch(gFontRadio) {
  61.         case kAppFont:
  62.             familyID = GetAppFont();
  63.             break;
  64.         case kTimes:
  65.             GetFNum("\pTimes",&familyID);            /* Zero (sys font) if not present */
  66.             break;
  67.         case kHelvetica:
  68.             GetFNum("\pHelvetica",&familyID);        /* Zero (sys font) if not present */
  69.             break;
  70.     }
  71.  
  72.     return familyID;
  73. }
  74.  
  75. /****************************************************************************************/
  76. void SetValue(DialogPtr theDialog,short itemNum,short value)
  77. {
  78.     short    aType;
  79.     Rect    aBox;
  80.     Handle    theItem;
  81.  
  82.     GetDialogItem(theDialog,itemNum,&aType,&theItem,&aBox);
  83.     SetControlValue((ControlHandle)theItem,value);
  84. }
  85.  
  86. /****************************************************************************************/
  87. void GetItemRect(DialogPtr theDialog,short itemNum,Rect *box)
  88. {
  89.     short    aType;
  90.     Handle    theItem;
  91.  
  92.     GetDialogItem(theDialog,itemNum,&aType,&theItem,box);
  93. }
  94.  
  95. /****************************************************************************************/
  96. void UserItem (DialogPtr theDialog, short itemNum, UserItemProcPtr theProc)
  97. {
  98.             short                aType;
  99.             Rect                aBox;
  100.             Handle                theItem;
  101.  
  102.     //
  103.     //    This is a cheesy hack. This function was not designed
  104.     //    to produce errors and I didn't feel like revising the
  105.     //    callers. So we "cache" the UPP because we know the
  106.     //    sequence in which we will be called. -- PG
  107.     //
  108.  
  109.     static    UserItemProcPtr        userItemProcPtr;
  110.     static    UserItemUPP            userItemUPP;
  111.  
  112.     if (userItemProcPtr != theProc)
  113.     {
  114.         userItemUPP = NewUserItemProc (theProc);
  115.         userItemProcPtr = theProc;
  116.     }
  117.  
  118.     GetDialogItem(theDialog,itemNum,&aType,&theItem,&aBox);
  119.     SetDialogItem(theDialog,itemNum,aType,(Handle)userItemUPP,&aBox);
  120. }
  121.  
  122. /****************************************************************************************/
  123. void InvalItem(DialogPtr theDialog,short itemNum,short hInset,short vInset)
  124. {
  125.     short    aType;
  126.     Rect    aBox;
  127.     Handle    theItem;
  128.  
  129.     GetDialogItem(theDialog,itemNum,&aType,&theItem,&aBox);
  130.     InsetRect(&aBox,hInset,vInset);
  131.     InvalRect(&aBox);
  132. }
  133.  
  134. /****************************************************************************************/
  135. pascal void BoxItem(WindowPtr theWindow,short itemNum)
  136. {
  137.     short    aType;
  138.     Rect    theBox;
  139.     Handle    aHandle;
  140.  
  141.     GetDialogItem(theWindow,itemNum,&aType,&aHandle,&theBox);
  142.     PenNormal();
  143.     ForeColor(blackColor);
  144.     
  145.     FrameRect(&theBox);
  146. }
  147.  
  148. /****************************************************************************************/
  149. pascal void GrayBoxItem(WindowPtr theWindow,short itemNum)
  150. {
  151.     short    aType;
  152.     Rect    theBox;
  153.     Handle    aHandle;
  154.  
  155.     GetDialogItem(theWindow,itemNum,&aType,&aHandle,&theBox);
  156.     PenNormal(); PenPat(&qd.gray);
  157.     ForeColor(blackColor);
  158.     
  159.     FrameRect(&theBox);
  160.     PenNormal();
  161. }
  162.  
  163. /****************************************************************************************/
  164. void TextParms(short code)
  165. {
  166.     static short txFont,txFace,txSize,txMode;
  167.     
  168.     if (code == kSave) {        /* Save current port's text parameters */
  169.         txFont = qd.thePort->txFont;
  170.         txFace = qd.thePort->txFace;
  171.         txSize = qd.thePort->txSize;
  172.         txMode = qd.thePort->txMode;
  173.     } else {                    /* Restore current port's text parameters */
  174.         TextFont(txFont);
  175.         TextFace(txFace);
  176.         TextSize(txSize);
  177.         TextMode(txMode);
  178.     }
  179. }
  180.